package service.impl;

import service.PromotionCalculate;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 打折促销
 */
public class DiscountPromotion implements PromotionCalculate {
    @Override
    public BigDecimal calculate(BigDecimal price) {
        //判断金额不为空，为空直接赋值为0，反之金额乘于0.8
        price = price==null?BigDecimal.ZERO:price.multiply(new BigDecimal(0.8)).setScale(2, RoundingMode.HALF_UP);
        return price;
    }

    @Override
    public String promotionName () {
        return "折扣";
    }
}
